# -*- coding: utf-8 -*-
# 该文件在宿主机执行，需要 root 权限

import os
from config import config, router


if __name__ == "__main__":
    config = config()

    """1. 关闭并清除 docker 容器"""
    os.system("sudo docker stop $(sudo docker ps -aq)")
    os.system("sudo docker rm $(sudo docker ps -aq)")

    """2. 清理网络"""
    nets = []
    for router in config.routers:
        for i in range(len(router.interfaces_ip)):
            net_name = router.get_network_name(i)
            if net_name not in nets:
                nets.append(net_name)
                l1 = net_name + '1'
                os.system(f"sudo ip link delete dev {l1}")